package com.ocom.webapi.controller;


import com.alibaba.fastjson.JSON;
import com.ocom.common.constant.WebApiServiceUrl;
import com.ocom.common.entity.payconfig.EntityPackageType;
import com.ocom.common.request.callpackage.*;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.ResultUtil;
import com.ocom.webapi.feign.PayConfigClientService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@PreAuthorize("@pms.hasRole('ROLE_WEB')" )
public class CallPackageController {


    @Autowired
    private PayConfigClientService payConfigClientService;
    /**
     * 通话套餐查询（CallPackagePage/onShow）
     * */
    @PostMapping(WebApiServiceUrl.Url_CallPackagePageOnShow)
    public Result onShow(@Validated @RequestBody OnShowRequest request){
        return payConfigClientService.getCallPackageConfig(request);
    }

    /**
     * 通话套餐新增（CallPackagePage/addConfig）
     * */
    @PostMapping(WebApiServiceUrl.Url_CallPackagePageAddConfig)
    public Result addConfig(@Validated @RequestBody AddConfigRequest request){
        EntityPackageType entityPackageType = JSON.parseObject(JSON.toJSONString(request), EntityPackageType.class);
        return payConfigClientService.addCallPackageConfig(entityPackageType);
    }

    /**
     * 通话套餐编辑（CallPackagePage/editConfig）
     * */
    @PostMapping(WebApiServiceUrl.Url_CallPackagePageEditConfig)
    public Result editConfig(@Validated @RequestBody EditConfigRequest request){
        EntityPackageType entityPackageType = JSON.parseObject(JSON.toJSONString(request), EntityPackageType.class);
        return payConfigClientService.editCallPackageConfig(entityPackageType);
    }

    /**
     * 通话套餐删除（CallPackagePage/deleteConfig）
     * */
    @PostMapping(WebApiServiceUrl.Url_CallPackagePageDeleteConfig)
    public Result deleteConfig(@Validated @RequestBody DeleteConfigRequest request){
        return payConfigClientService.deleteCallPackageConfig(request);
    }

    /**
     * 修改通话套餐内容（modifyCallPackageDetail）
     * */
    @PostMapping(WebApiServiceUrl.Url_modifyPackageTypeDetail)
    public Result modifyCallPackageDetail(@Validated @RequestBody ModifyCallPackageDetailRequest request){
        return payConfigClientService.saveCallPackageDetail(request);
    }

}
